import Vue from 'vue'
import UUID from 'vue-uuid'
import ElementUI from 'element-ui'
import App from './App.vue'
import router from './router'
import store from './vuex/index'
import axios from 'axios'
import VueWorker from 'vue-worker'
import vClickOutside from 'v-click-outside'

// import VueLazyComponent from '@xunlei/vue-lazy-component'
// import 'element-ui/lib/theme-chalk/index.css'
// import vuescroll from 'vuescroll'
import './theme/index.css'
import {
  getStorage
} from './js/utils'
import contentmenu from 'v-contextmenu'
import 'v-contextmenu/dist/index.css'

Vue.use(vClickOutside)
Vue.use(UUID)

// Vue.use(VueLazyComponent)

// Vue.use(vuescroll)

Vue.use(ElementUI)

Vue.use(contentmenu)

Vue.use(VueWorker)

Vue.prototype.$http = axios
Vue.config.productionTip = false

// 做登录校验
router.beforeEach((to, from, next) => {
  if (to.path === '/') {
    next({
      path: '/home'
    })
  }
  if (to.matched.some(record => record.meta.requireAuth)) {
    if (getStorage('aillo_token')) {
      // 判断当前的token是否存在 ； 登录存入的token
      next()
    } else {
      next({
        path: '/login',
        query: {
          redirect: to.fullPath
        } // 将跳转的路由path作为参数，登录成功后跳转到该路由
      })
    }
  } else {
    next()
  }
})

new Vue({
  el: '#app',
  router,
  store,
  render: h => h(App)
}).$mount('#app')
